/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.refunite.mobile.s60.dto;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;

/**
 *
 * @author I040022
 */
public class ServerConfigData {
    private String serverAddress;
    private String username;
    private String password;

    public ServerConfigData(String serverURL, String username, String password){
        this.serverAddress = serverURL;
        this.username = username;
        this.password = password;
    }
    public static ServerConfigData unmarshall(byte[] byteArray){
        try{
            ByteArrayInputStream bis = new ByteArrayInputStream(byteArray);
            DataInputStream dis = new DataInputStream(bis);
            String serverURL = dis.readUTF();
            String username = dis.readUTF();
            String password = dis.readUTF();
            return new ServerConfigData(serverURL, username, password);
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public static byte[] marshall(String serverURL, String username, String password){
        try{
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            dos.writeUTF(serverURL);
            dos.writeUTF(username);
            dos.writeUTF(password);
            dos.close();
            return bos.toByteArray();
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }
    public String getPassword() {
        return password;
    }

    public String getServerAddress() {
        return serverAddress;
    }

    public String getUsername() {
        return username;
    }



    
}
